// 2014-02-01 Tyrghen
//---------------------------------------------
// Usage:
//  [] call edt_fnc_;
//---------------------------------------------
// Purpose:
// 
// 
// Parameters:
// - 
//
// Returns:
// 
//---------------------------------------------
// Objectif:
// 
//
// Paramètres:
// - 
//
// Renvoie:
// 
//---------------------------------------------

//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "editor\fn_activate.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

if (!isServer) exitWith {TRACE("Not Server")};

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_type","_marker","_activated","_error","_obj_params","_tmf_params","_shared_val","_activated_title","_deactivated_title"];
DEFAULT_PARAM(_type,0,"");
DEFAULT_PARAM(_marker,1,"");
DEFAULT_PARAM(_activated,2,"");
DEFAULT_PARAM(_activated_msg,3,ARR_1("STR_TMF_TARGET_ACTIVATED"));
DEFAULT_PARAM(_deactivated_msg,4,ARR_1("STR_TMF_TARGET_DEACTIVATED"));
DEFAULT_PARAM(_shared_val,5,false);
DEFAULT_PARAM(_one_way,6,false);
DEFAULT_PARAM(_activated_title,7,"");
DEFAULT_PARAM(_deactivated_title,8,"");

_obj = objNull;
_is_valid = true;

if (AND_ALSO(IS_STRING(_type),(_type == ""))) then {
	_is_valid = false;
};
if (AND_ALSO(IS_STRING(_type),(_type isKindOf "Man" || _type isKindOf "LandVehicle" || _type isKindOf "Air" || _type isKindOf "Ship"))) then {
	_is_valid = false;
};
if (AND_ALSO(IS_STRING(_type),IS_STRING(_marker))) then {
	_is_valid = _is_valid && _marker != "";
};
if (AND_ALSO(IS_STRING(_type),IS_ARRAY(_marker))) then {
	_is_valid = _is_valid && count _marker < 2;
};
if (AND_ALSO(IS_OBJECT(_type),(isnull _type))) then {
	_is_valid = false;
};
_activated = _activated call FFUNC(getStringVar);

if (_is_valid) then {
	_obj_params = [];
	_obj_params set [TMF_VEH_PARAMS_TYPE, _type];
	_obj_params set [TMF_VEH_PARAMS_POS, _marker];

	_tmf_params = [];
	// If not one way, both messages are wanted
	// If one way, we only want the message which is the opposite of the shared val
	_tmf_params = [_tmf_params,"ACTIVATION_MSG",_activated_msg] call FFUNC(hashSet);
	_tmf_params = [_tmf_params,"DEACTIVATION_MSG",_deactivated_msg] call FFUNC(hashSet);

	if (_activated_title == "" && (!_one_way || _shared_val)) then {
		_activated_title = "STR_TMF_ACTIVATE_DEFACTIONON";
	};
	if (_deactivated_title == "" && (!_one_way || !_shared_val)) then {
		_deactivated_title = "STR_TMF_ACTIVATE_DEFACTIONOFF";
	};
	_tmf_params = [_tmf_params,"ACTIVATED_TITLE",_activated_title] call FFUNC(hashSet);
	_tmf_params = [_tmf_params,"DEACTIVATED_TITLE",_deactivated_title] call FFUNC(hashSet);

	_tmf_params = [_tmf_params,"SHARED_VAR",_activated] call FFUNC(hashSet);
	_tmf_params = [_tmf_params,"SHARED_VAR_VAL",_shared_val] call FFUNC(hashSet);
	//_tmf_params = [_tmf_params,"ACTIVATED_CODE",""] call FFUNC(hashSet);
	//_tmf_params = [_tmf_params,"DEACTIVATED_CODE",""] call FFUNC(hashSet);

	_obj = [_obj_params,"ACTIVATE",_tmf_params] call FFUNC(CreateMissionObject);
	TRACE_1("End",ARR_3(_obj, typeof _obj, getPos _obj));
} else {
	ERROR("Invalid Parameters");
};
TMFPROFILERSTOP;
_obj